var app = getApp(),
  $ = require("../../utils/httpHelper.js"),
  WxNotificationCenter = require("../../WxNotificationCenter/WxNotificationCenter.js")//通知传参
var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
Page({
  data: {
    objarr: [],
    position:[],
    width:0,
    imgheight:0,
    indexdata:{},
    height:0,
    currentTab:1,
    page: 1,
    pagesize: 5,
    totalpage: 0,//最大页数
    nomore: true,
  },
  onShareAppMessage: function (res) {
    let member_id = app.globalData.userInfo.member_id
    return {
      title: '成纪先锋微平台',
      path: '/pages/public/pulic?inviter_id=' + member_id,
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  onLoad: function (options) {
    var that = this;
    console.log(wx.getStorageSync('rd_session'))
    
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        that.setData({
           width: res.windowWidth,
           height:res.windowHeight })
      }
    })

    let par = {
      rd_session: wx.getStorageSync("rd_session"),
      page: this.data.page,
      page_size: this.data.page_size,
    }
    app.ajax("mp_list", par, (data, err) => {
      if (data.result == 'success') {
        this.setData({
          objarr: data.data.list,
          totalpage: data.data.total_page
        })
      }
    })
  },
  clicktab(e) {
    let tab = e.currentTarget.dataset.tab
    if (this.data.currentTab != tab) {
      this.setData({
        currentTab: tab,
        page: 1,
      })
      //this.getData(tab)
    }
  },
  //滑动到底部 上拉加载
  scrollBottom: function () {
    this.data.page++
    if (this.data.page > this.data.totalpage) {
      this.setData({
        nomore: false
      })
    } else {
      let params = {
        rd_session: wx.getStorageSync("rd_session"),
        page: this.data.page,
        page_size: this.data.pagesize
      }
      app.ajax("mp_list", params, (data, err) => {
        let arr = this.data.objarr;
        for (let item of data.data.list) {
          arr.push(item);
        }
        this.setData({
          objarr: arr
        })
      })
    }

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  toKecheng(){
    wx.switchTab({
      url: '/pages/kecheng/kecheng'
    })
  },
  tozixun(){
    wx.navigateTo({
      url: '/pages/zixun/zxlist',
    })
  },
  tosearch(){
    wx.navigateTo({
      url: '/packageA/pages/search/search',
    })
  },
  toAbout(e) {
    // 只允许从相机扫码
    // wx.scanCode({
    //   onlyFromCamera: true,
    //   success: (res) => {
    //     console.log(res)
    //   }
    // })
    wx.navigateTo({
      url: '/pages/yeni/about',
    })
  },
  toyhq(){
    wx.navigateTo({
      url: '/pages/yhq/getyhq',
    })
  },
  shangc(e) {
    let id = e.currentTarget.dataset.id
    app.globalData.shangc_id = id
    wx.switchTab({
      url: '/pages/shangc/shangc',
    })
  },
  tovedio(){
    wx.navigateTo({
      url: '/pages/vedio/vediolist',
    })
  },
  tozs(){
    wx.navigateTo({
      url: '/pages/yeni/zhaoshang',
    })
  },
  topl(){
    wx.navigateTo({
      url: '/pages/pl/pl',
    })
  },
  togoodsinfo(e){
    let id = e.currentTarget.dataset.id
    let status = e.currentTarget.dataset.status
    wx.navigateTo({
      url: '/pages/goods/goods_detail_buy?id=' + id + '&status=' + status,
    })
  },
  chooseshop(){
    wx.navigateTo({
      url: '/pages/index/shops?shopname='+this.data.shopname,
    })
  },
  todetail(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/zixun/zxdetail?id=' + id,
    })
  },
  imageLoad(e) {
    let that = this
    this.setData({
      imgheight: app.fixImgW(e, that.data.width),
    })
  },

 
  
});